package com.stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/*
* 1,ID必须是偶数
* 2，年龄必须大于23
* 3，用户名转为大写字母
* 4，用户名字倒叙
* 5，只输出一个用户
* */

public class Test {

    public static void main(String[] args) {

        User u1 = new User(1,"a",23);
        User u2 = new User(2,"b",24);
        User u3 = new User(3,"c",25);
        User u4 = new User(4,"d",26);
        User u5 = new User(5,"e",27);
        //集合就是存储
        List<User> users = Arrays.asList(u1, u2, u3, u4, u5);

        users.stream()
                .filter(user -> {return user.getId()%2==0;})
                .filter(user -> {return user.getAge()>23;})
                .map(user -> {return user.getName().toUpperCase();})
                .sorted((uu1,uu2)->{return uu2.compareTo(uu1);})
                .limit(1)
                .forEach(System.out::println);
    }
}

@Data
@NoArgsConstructor
@AllArgsConstructor
class User{
    private int id;
    private String name;
    private int age;
}
